package com.weiaibenpao.demo.chislim.ui.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.weiaibenpao.demo.chislim.R;
import com.weiaibenpao.demo.chislim.bean.SportHistoryBean;

import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * Created by lenovo on 2018/1/8.
 */

public class SportHistoryAdapter  extends BaseQuickAdapter<SportHistoryBean.ListBean, BaseViewHolder> {
    private DecimalFormat mDecimalFormat = new DecimalFormat("0.00");
    private SportHistoryDateAdapter sportHistoryDateAdapter;
    private Context mContext;

    public SportHistoryAdapter(Context context) {
        super(R.layout.djq_sporthistory_month_item, null);
        mContext = context;
    }


    @Override
    protected void convert(BaseViewHolder helper, SportHistoryBean.ListBean item) {
        helper.setText(R.id.yearTitle,item.getMonthDate());
        String hour = mDecimalFormat.format(item.getMonthTime()/3600f);
        helper.setText(R.id.infoIntro,item.getMonthNumber() + "次跑步 " + hour+ "小时 " + item.getMonthDistance() + "公里");
        RecyclerView subList = helper.getView(R.id.myDateList);
        sportHistoryDateAdapter = new SportHistoryDateAdapter(mContext);//需要每次new否则不显示!
        subList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        subList.setAdapter(sportHistoryDateAdapter);
        sportHistoryDateAdapter.setData((ArrayList<SportHistoryBean.ListBean.SportsBean>) item.getSports());
    }

}
